﻿using System;
using System.Collections.Generic;
using System.ServiceModel.Syndication;
using System.Xml;
using EDXLSharp;

namespace GISUtil
{
  public class OtherXMLWrapper : IContentObject, IComposable, IGeoRSS
  {
    private XmlNode data;
    private string description;
    private List<string> contentKeywords;

    public OtherXMLWrapper(List<string> keywords, string description)
    {
      this.contentKeywords = keywords;
      this.description = description;
    }

    

    // Summary:
    //     Reads the input XML into the internal copy. Uses the Clone operation on the root XmlNode
    //
    // Parameters:
    //   rootnode:
    //     String of XML CoT Data
    public void ReadXML(XmlNode rootnode)
    {
      data = rootnode.Clone();
    }

    /// <summary>
    /// Override of IContentObject Interface Function
    /// </summary>
    /// <param name="ckw">ValueLIst Object for Content Keywords</param>
    /// <returns>String to Process cks Value From</returns>
    public string SetContentKeywords(ValueList ckw)
    {
      ckw.ValueListURN = EDXLConstants.ContentKeywordListName;
      ckw.Value.AddRange(contentKeywords);
      
      return "Other XML Type Message";
    }

    /// <summary>
    /// Converts This IComposableMessage Into A Geo-RSS SyndicationItem
    /// </summary>
    /// <param name="items">Pointer to a Valid List of Syndication Items to Populate</param>
    /// <param name="linkUID">Unique Identifier to Link This Item To</param>
    public void ToGeoRSS(List<SyndicationItem> items, Guid linkUID)
    {
      SyndicationItem myitem = new SyndicationItem();
      myitem.Authors.Add(new SyndicationPerson("Unknown", "Unknown", String.Empty));
      myitem.Categories.Add(new SyndicationCategory("XML", EDXLConstants.SyndicationCategoryScheme, EDXLConstants.SyndicationCategoryLabel));
      //this.WriteGeoRSSGML(myitem); // would be used to inject geographic information if it was available
      myitem.Copyright = new TextSyndicationContent(EDXLConstants.SyndicationCopyright);
      myitem.LastUpdatedTime = DateTime.Now;
      myitem.Links.Add(new SyndicationLink(new Uri(EDXLConstants.SyndicationLinkBaseURI + "HTML/" + linkUID.ToString())));
      myitem.PublishDate = DateTime.Now;
     
      myitem.Summary = new TextSyndicationContent("A Non-EDXL message in namespace " + data.NamespaceURI);
      if (description != null && description != "")
      {
        // use the description as the title
        myitem.Title = new TextSyndicationContent(description);
      }
      else
      {
        // use the node type as the title
        myitem.Title = new TextSyndicationContent(data.Name + " XML");
      }
      
      myitem.Content = new TextSyndicationContent("OtherXML");
      items.Add(myitem);
    }

    /// <summary>
    /// Validates This Message to the schema
    /// </summary>
    /// <param name="xmldata">XML Data to Validate</param>
    public void ValidateToSchema(string xmldata)
    {
    }

    /// <summary>
    /// Writes This Object to an Existing XML Document
    /// </summary>
    /// <param name="xwriter">Pointer to the XMLWrite Writing the Document</param>
    public void WriteXML(XmlWriter xwriter)
    {
      data.WriteTo(xwriter);
    }

    public void Validate()
    {
      throw new NotImplementedException();
    }

    public void ValidateToSchema()
    {
      throw new NotImplementedException();
    }

    public DateTime ExpiresDateTime
    {
      get { return default(DateTime); }
    }
  }
}
